package com.mmbang.search;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mmbang.util.StringOperation;

/**
 * 
 * @author Administrator
 *接收用户端的请求
 */
public class SearchApi extends HttpServlet
{

	public void doPost(HttpServletRequest request, HttpServletResponse response)
					throws IOException, ServletException
	{
		doGet(request, response);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
					throws IOException, ServletException
	{
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		//表示页面端传过来的不完整的字符串，用于和服务器端的单词进行匹配
		
		//String word = request.getParameter("word");
		String keyword = StringOperation.getDisplayString(request.getParameter("keyword"));
		String page_num = request.getParameter("page");
		String info_type = request.getParameter("info_type");
		
		System.out.println("keyword:" + keyword);
		
		//将字符串保存在request中
		request.setAttribute("keyword", keyword);
		request.setAttribute("page", page_num);
		request.setAttribute("info_type", info_type);
		
		//将请求转发给视图层，所谓的Ajax视图层不返回页面，只返回数据，可以称作数据层
		request.getRequestDispatcher("search_api.jsp").forward(request, response);
	}
}
